﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace 页面传递
{
    public class ViewManager
    {
        static ViewManager()
        {

        }
        private ViewManager()
        {
            Resource = new ResourceDictionary();
        }
        private class InnerClass
        {
            static InnerClass()
            {

            }
            internal static readonly ViewManager view = new ViewManager();
        }
        public static ViewManager Instance { get => InnerClass.view; }

        public ResourceDictionary Resource
        {
            get;
            set;
        }
        public ResourceDictionary SetView(ViewFrame Data)
        {
            if (Data != null)
            {
                if (!ViewContent.ContainsValue(Data))
                {
                    ViewContent.Add(ViewContentCount, Data);
                    ViewContentCount += 1;
                }
                DataTemplateKey key = new DataTemplateKey(Data.GetType());
                DataTemplate template = new DataTemplate(Data.GetType());
                template.VisualTree = new FrameworkElementFactory(Data.ViewType);
                Resource.Add(key, template);
            }
            return Resource;
        }
        public int ViewContentCount { get; set; } = 0;
        public Dictionary<int, object> ViewContent
        {
            get;
            set;
        } = new Dictionary<int, object>();
    }
}
